/**
 * ThumbnailUploadDAO.java
 * Creates a data access object (DAO) for a thumbnail image
 * data transfer object (DTO).
 */
package com.example.myproject;

import java.util.List;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.util.DAOBase;

public class ThumbnailUploadDAO extends DAOBase{

    static {
        ObjectifyService.register(ThumbnailUploadDTO.class);
    }

    /**
     * Saves a ThumbnailUploadDTO to the blobstore.
     * @param dto The thumbnail image object to be saved.
     */  
    public ThumbnailUploadDTO save(ThumbnailUploadDTO dto) {
        ofy().put(dto);
        return dto;
    }
 
    /**
     * Retrieves ThumbnailUploadDTOs from the blobstore with matching IDs.
     * @param id Supplied search parameter.
     * @return Returns a key map of ThumbnailUploadDTOs matching id.
     */	
    public ThumbnailUploadDTO findById(Long id) {
        Key<ThumbnailUploadDTO> key = new Key<ThumbnailUploadDTO>(ThumbnailUploadDTO.class, id);
        return ofy().get(key);
    }
    
	/**
	 * Retrieves a ThumbnailUploadDTOs from the blobstore with matching parent ID. 
	 * @param parentId Supplied search parameter.
	 * @return Returns matching ThumbnailUploadDTO.
	 */
    public ThumbnailUploadDTO findByParentId(Long parentId) {
    	ThumbnailUploadDTO Thumbnail = ofy().query(ThumbnailUploadDTO.class).filter("parentId ", parentId).get();
        return Thumbnail;
    }    
    
    /**
     * Retrieves a list of all ThumbnailUploadDTOs in the blobstore.
     * @return List containing all ThumbnailUploadDTOs in the blobstore.
     */    
	public List<ThumbnailUploadDTO> list() 
	{		
		List<ThumbnailUploadDTO> alist = ofy().query(ThumbnailUploadDTO.class).list();
		return alist;
	}

    /**
     * Retrieves a list of all ThumbnailUploadDTOs in the blobstore whose genre
     * matches the supplied caption.
     * @param caption Supplied search parameter.
     * @return List containing ThumbnailUploadDTOs with matching captions.
     */		
	public List<ThumbnailUploadDTO> listByCaption(String caption) 
	{		
		List<ThumbnailUploadDTO> alist = ofy().query(ThumbnailUploadDTO.class).filter("caption", caption).list();
		return alist;
	}

    /**
     * Deletes a ThumbnailUploadDTO from the blobstore, specified by parentId.
     * @param parentId Supplied parentId of the ThumbnailUploadDTO to be deleted.
     */
	public void deleteByParentId(Long parentId) 
	{		
		ThumbnailUploadDTO Thumbnail = ofy().query(ThumbnailUploadDTO.class).filter("parentId ", parentId).get();
		ofy().delete(Thumbnail);
	}
	
}
